<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        .box {
            width: 1200px;
            margin: 0 auto;
        }

        .box .header,
        .footer {
            height: 500px;
            width: 1200px;
            background-color: springgreen;
            font-size: 80px;
            text-align: center;
            line-height: 500px;
            color: #fff;
        }

        ul,
        li {
            list-style: none;
        }

        ul {
            display: flex;
            flex-wrap: wrap;
            justify-content: space-between;
        }

        ul>li {
            width: 280px;
            height: 500px;
            border: 1px solid gray;
            margin-top: 10px;
        }

        img {
            width: 280px;
            height: 350px;
        }

        ul>li>p {
            padding: 0 10px;
        }
        .loading{
            height: 200px;
            width: 1200px;
            margin: 0 auto;

            display: none;
        }
        .loading img{
            width: 100%;
            height: 100%;
            display: block;
        }
    </style>
</head>

<body>
    <div class="box">
        <div class="header">头部</div>
        <div class="content">
            <ul>
                <!-- <li>
                    <img src="" alt="">
                    <p>2020西太湖国际应跃进</p>
                    <p>城市:常州</p>
                    <p>地址:常州席太平个地方回家看电视</p>
                    <p>价格:23323</p>
                    <p>演出时间:2022</p>
                </li> -->
            </ul>
        </div>
        <div class="loading">
            <img src="https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fpic2.zhimg.com%2Fv2-af22afd5b8cae4f20da1fe4bd73c6848_b.gif&refer=http%3A%2F%2Fpic2.zhimg.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1656571706&t=732cfa44a32bb0ad0c75d2edb48021a4" alt="">
        </div>
        <div class="footer">尾部</div>
    </div>
    <script src="./dm_list.js"></script>
    <script>
        /* 默认显示一页
           一页显示8个
        */
        var current = 1;
        var pageNum = 8;
        var ul = document.querySelector("ul")
        var loading = document.querySelector(".loading")

        function render() {
            var arr = list.slice((current - 1) * pageNum, (current * pageNum))
            var str = ""
            arr.forEach(function (item) {
                str += `
                <li>
                    <img src="${item.pic}" alt="">
                    <p>${item.name}</p>
                    <p>城市:${item.city}</p>
                    <p>地址:${item.address}</p>
                    <p>价格:${item.price}</p>
                    <p>演出时间:${item.showTime}</p>
                </li>
            `
            })
            /* 
                每触底一次,就想服务器发送一个请求,需要重新获取新的数据加载,那么我们就将进行的数据与老的数据给拼接起来
                那我们现在没有服务器,那么我们需要使用数组来进行模拟获取数据
            */
            ul.innerHTML += str;
        }
        render();





        /* 触底效果 */
        window.onscroll = function () {
            //获取卷去的高度
            var scrollTop = document.documentElement.scrollTop || document.body.scrollTop
            //浏览器的可视高度
            var documentHeight = document.documentElement.clientHeight
            //ul自己的高度
            var ulHeight = ul.offsetHeight
            //头部的高度
            var headHeight = ul.offsetTop
            // console.log(scrollTop,documentHeight,ulHeight,headHeight);
            if (scrollTop + documentHeight > ulHeight + headHeight) {
                loading.style.display = "block"
                setTimeout(function(){
                    //重新加载数据
                    current ++
                    render();
                },2000)
            }
        }
    </script>
</body>

</html>